import { Api } from "../../api/api"
import check_utils from "../../components/custom_views/check_utils"
import { CustomDict } from "../../components/custom_views/custom_dict"
import { Dict } from "../../components/custom_views/dict"

export const getDefaultPostDto = function(postType){
    let postDto = {}
    Object.assign(postDto, defaultPostSellDto, {'postType': postType,})
    postDto.labelDtoList = []
    return postDto
}

export const defaultPostSellDto = {
    // private Long @ApiModelProperty(value = "用户uuid", example = "1111")
    userId: null,

    /**
     * 主要业务类型
     * 转店/找店
     * 转设备/找设备
     * 人才服务
     */
    // private Integer @ApiModelProperty(value = "主要业务类型", example = "1201")
    postMainType: null,

    /**
     * 特定业务类型
     * 转店 找店 转设备 找设备
     */
    // private Integer @ApiModelProperty(value = "特定业务类型", example = "120102")
    postType: Dict.PostMainTypeEnum.Shop.value,

    /**
     * 务工人姓名
     */
    // private String @ApiModelProperty(value = "务工人姓名", example = "张三")
    name:'',

    /**
     * 店铺/设备名称；务工标题
     */
    // private String @ApiModelProperty(value = "店铺/设备名称；务工标题", example = "长虹洗衣机")
    title:'',

    /**
     * 业态类型
     */
    // private Integer @ApiModelProperty(value = "业态类型", example = "1")
    industryId:null,

    /**
     * 省份
     */
    // private String @ApiModelProperty(value = "省份", example = "河南")
    province:'北京市',

    /**
     * 城市
     */
    // private String @ApiModelProperty(value = "城市", example = "信阳")
    city:'北京市',

    /**
     * 城市编码
     */
    // private String @ApiModelProperty(value = "城市", example = "111111")
    cityCode:'1101',

    /**
     * 区县
     */
    // private String @ApiModelProperty(value = "区县", example = "息县")
    area:'',

    /**
     * 区县编码
     */
    // private String @ApiModelProperty(value = "区县编码", example = "222222")
    areaCode:'',

    /**
     * 街道
     */
    // private String @ApiModelProperty(value = "街道", example = "黄渠街道")
    street:'',

    /**
     * 详细地址
     */
    // private String @ApiModelProperty(value = "详细地址", example = "黄渠街道138号")
    address:'',

    /**
     * contact_phone
     */
    // private String @ApiModelProperty(value = "contact_phone", example = "18141928947")
    contactPhone:'',

    /**
     * 微信号
     */
    // private String @ApiModelProperty(value = "微信号", example = "hulinxiao007")
    wechatNumber:'',

    /**
     * 日薪、月薪、年薪，默认月薪
     */
    // private Integer @ApiModelProperty(value = "日薪、月薪、年薪，默认月薪", example = "20000")
    salaryPeriod:null,

    /**
     * 月薪（元）
     */
    // private Integer @ApiModelProperty(value = "月薪（元）", example = "20000")
    salary:null,
    // private Integer @ApiModelProperty(value = "查询最低月薪（元）", example = "20000")
    salaryMin:null,
    // private Integer @ApiModelProperty(value = "查询最高月薪（元）", example = "20000")
    salaryMax:null,

    /**
     * 最低租金，即月租金（元）
     */
    // private Integer @ApiModelProperty(value = "最低租金，即月租金（元）", example = "35000")
    lowerRent:null,
    // private Integer @ApiModelProperty(value = "查询最低月租金", example = "20000")
    lowerRentMin:null,
    // private Integer @ApiModelProperty(value = "查询最高月租金", example = "20000")
    lowerRentMax:null,

    /**
     * 暂时不用
     */
    // private Integer @ApiModelProperty(value = "暂时不用", example = "0")
    upperRent:null,
    // private Integer @ApiModelProperty(value = "查询最低月租金", example = "20000")
    upperRentMin:null,
    // private Integer @ApiModelProperty(value = "查询最高月租金", example = "20000")
    upperRentMax:null,

    /**
     * 免租金天数
     */
    // private Integer @ApiModelProperty(value = "免租金天数", example = "50")
    freeRentDays:null,

    /**
     * 转让费（元）
     */
    // private Integer @ApiModelProperty(value = "转让费(元)", example = "100000")
    transferFee:null,

    // private Integer @ApiModelProperty(value = "查询最低转让费", example = "20000")
    transferFeeMin:null,
    // private Integer @ApiModelProperty(value = "查询最高转让费", example = "20000")
    transferFeeMax:null,

    /**
     * 转让费面议
     * 0-否 1-是
     */
    // private Integer @ApiModelProperty(value = "转让费面议标志", example = "1")
    transferFeeDiscuss: 0,

    /**
     * 是否中介帮转
     */
    // private Integer @ApiModelProperty(value = "中介帮转标志", example = "1")
    needAgent:null,

    /**
     * 中介费
     */
    // private Integer @ApiModelProperty(value = "中介费", example = "9000")
    agentFee:null,

    // private Integer @ApiModelProperty(value = "查询最低中介费", example = "20000")
    agentFeeMin:null,
    // private Integer @ApiModelProperty(value = "查询最高中介费", example = "20000")
    agentFeeMax:null,

    /**
     * 店铺标签；招工务工标签
     */
    // private List<LabelDto> @ApiModelProperty(value = "发帖标签列表", example = "")
    labelDtoList: [],

    /**
     * 用户指标数据 List
     */
    // @ApiModelProperty(value = "用户指标数据", example = "")
    // private List<MetricRecordDto> MetricRecordList;
    // private MetricRecordDtoMap @ApiModelProperty(value = "用户指标数据map", example = "")
    metricRecordDtoMap: {
        like: 0, //是否点赞
        collect: 0, //是否收藏
        focus: 0, //是否关注
        likeNumber: 0, //点赞数
        collectNumber: 0, //收藏数
        focusNumber: 0, //关注数
        shareNumber: 0,  //分享数
        beenCollectNumber: 0, // 被收藏的总数
        beenAddCollectNumber: 0, //新增的被收藏的数
        beenViewNumber: 0, // 被浏览的总数
        beenAddViewNumber: 0, //当日新增的被浏览的数
    },

    // private MetricRecordDto @ApiModelProperty(value = "用户指标数据map", example = "")
    metricRecordDto:{},

    // private Integer @ApiModelProperty(value = "指标类型", example = "4")
    metricType:null,


    /**
     * 门面照；设备外观；招工信息封面图；形象照片
     */
    // private String @ApiModelProperty(value = "门面照；设备外观；招工信息封面图；形象照片", example = "pppoo")
    facadePicture:'',


    /**
     * 店内环境；设备细节
     */
    // private String @ApiModelProperty(value = "店内环境；设备细节照片", example = "pppooyy")
    shopInsidePicture:'',

    /**
     * 周边环境；设备材料相关证照
     */
    // private String @ApiModelProperty(value = "周边环境；设备材料相关证照", example = "pppooyyu")
    shopOutsidePicture:'',

    /**
     * 统一所有证件相关照片
     */
    // private String @ApiModelProperty(value = "统一所有证件相关照片", example = "kkkjjju")
    licensePicture:'',

    /**
     * 店铺营业执照
     */
    // private String @ApiModelProperty(value = "店铺营业执照", example = "kkkjjjui")
    businessLicensePicture:'',

    /**
     * 卫生许可照
     */
    // private String @ApiModelProperty(value = "卫生许可照", example = "kkkjhjjui")
    healthLicensePicture:'',

    /**
     * 餐饮许可
     */
    // private String @ApiModelProperty(value = "餐饮许可", example = "kkkjlhjjui")
    foodLicensePicture:'',

    /**
     * 食品加工许可
     */
    // private String @ApiModelProperty(value = "食品加工许可", example = "hhhjjk")
    foodProcessLicensePicture:'',

    /**
     * 食品流通许可
     */
    // private String @ApiModelProperty(value = "食品流通许可", example = "oorrt")
    foodCirculeLicensePicture:'',

    /**
     * 其他证件照片
     */
    // private String @ApiModelProperty(value = "其他证件照片", example = "fffkjh")
    otherLicensePicture:'',

    /**
     * 转店描述；设备描述；招工需求；务工需求
     */
    // private String @ApiModelProperty(value = "转店描述；设备描述；招工需求；务工需求", example = "饭店招人需要小工")
    content:'',


    /**
     * 店铺两点；个人技能亮点
     * 
     */
    // private String @ApiModelProperty(value = "店铺两点；个人技能亮点", example = "做面点")
    contentFeature:'',

    /**
     * 是否平台推荐
     */
    // private Integer @ApiModelProperty(value = "平台推荐标志", example = "1")
    recommend:null,

    /**
     * 是否曝光：默认0；
     */
    // private Integer @ApiModelProperty(value = "曝光标志", example = "0")
    exposure:null,
    /**
     * 曝光开始时间
     */
    // private Date @ApiModelProperty(value = "曝光开始时间", example = "2023-09-08")
    exposureStartTime:null,

    /**
     * 曝光结束时间
     */
    // private Date @ApiModelProperty(value = "曝光开始时间", example = "2023-09-09")
    exposureEndTime:null,

    /**
     * 是否有火标识
     */
    // private Integer @ApiModelProperty(value = "有火标志", example = "0")
    fireLogo:null,

    /**
     * 火标识开始时间
     */
    // private Date @ApiModelProperty(value = "火标识开始时间", example = "2023-09-29")
    fireLogoStartTime:'',

    // private Date @ApiModelProperty(value = "火标识结束时间", example = "2023-10-29")
    fireLogoEndTime:'',
    // private UserDto @ApiModelProperty(value = "用户信息", example = "2")
    userDto:{},
    // private Date @ApiModelProperty(value = "创建时间", example = "2")
    createTime:null,
    // private Date @ApiModelProperty(value = "查询开始创建时间", example = "2")
    createTimeStart:null,
    // private Date @ApiModelProperty(value = "查询截止创建时间", example = "2")
    createTimeEnd:null,
    // private Date @ApiModelProperty(value = "更新时间", example = "2")
    updateTime:null,
    // private Date @ApiModelProperty(value = "查询开始更新时间", example = "2")
    updateTimeStart:null,
    // private Date @ApiModelProperty(value = "查询截止更新时间", example = "2")
    updateTimeEnd:null,
    // private Integer @ApiModelProperty(value = "是否平台验证", example = "2")
    platformVerify:null,
    // private Integer @ApiModelProperty(value = "评论数", example = "2")
    commentNumber:null,
    // private Integer @ApiModelProperty(value = "未读留言数", example = "2")
    unreadCommentNumber:null,
    // private Integer @ApiModelProperty(value = "只查询我留言过的数据", example = "2")
    onlyHasComment:null,
    // private Integer @ApiModelProperty(value = "浏览量", example = "2")
    viewNumber:null,
    // private Integer @ApiModelProperty(value = "是否优选择", example = "2")
    highQuality:null,
    // private Integer @ApiModelProperty(value = "审核状态", example = "2")
    postStatus:null,
    postStatusDesc:'',
    // private Integer @ApiModelProperty(value = "店铺面积", example = "2")
    acreage:null,
    lowerAcreage:null,
    upperAcreage: null,
    shopVideo: '',
    shopAudio: '',
    smokeBusinessLicensePicture: '',
    wineBusinessLicensePicture: '',
    foodBusinessLicensePicture: '',
    envLicensePicture: '',
    postScore: ''
}

export let checkBuy = function(postDto){

    if(!check_utils.isNotEmptyWithSomeKey(postDto, ['province', 'city', 'cityCode', 'area', 'areaCode', 'street'])){
        check_utils.showCustToast('区域、街道信息不能为空')
        return false
    }
    // 计划经营
    if(check_utils.isEmpty(postDto.industryId)){
        check_utils.showCustToast('商铺类型不能为空')
        return false
    }
    // 商铺类型
    // if(check_utils.isEmpty(postDto.shopType)){
    //     check_utils.showCustToast('商铺类型不能为空')
    //     return false
    // }
    // 面积要求
    if(check_utils.isEmpty(postDto.lowerAcreage) || check_utils.isEmpty(postDto.upperAcreage)){
        check_utils.showCustToast('面积要求不能为空')
        return false
    }
    // 租金预算
    if(check_utils.isEmpty(postDto.lowerRent) || check_utils.isEmpty(postDto.upperRent)){
        check_utils.showCustToast('租金预算不能为空')
        return false
    }
    // 是否接受转让费
    if(check_utils.isEmpty(postDto.transferFeeDiscuss)){
        check_utils.showCustToast('请选择是否接受转让费')
        return false
    }
    // 联系电话
    if(check_utils.isEmpty(postDto.contactPhone)){
        check_utils.showCustToast('联系电话不能为空')
        return false
    }
    if(!check_utils.isMobilePhone(postDto.contactPhone)){
        check_utils.showCustToast('联系电话格式有误')
        return false
    }
    return true
}


export let checkBase = function(postDto){
    console.log('checkbase校验', postDto)
    if(!check_utils.isNotEmptyWithSomeKey(postDto, ['province', 'city', 'cityCode', 'area', 'areaCode', 'street'])){
        check_utils.showCustToast('区域、街道信息不能为空')
        return false
    }
    if(check_utils.isEmpty(postDto.address) || postDto.address.length < 5){
        check_utils.showCustToast('地址不能为空且需至少5个汉字')
        return false
    }
    // 计划经营
    if(check_utils.isEmpty(postDto.industryId)){
        check_utils.showCustToast('商铺类型不能为空')
        return false
    }
    // 商铺类型
    // if(check_utils.isEmpty(postDto.shopType)){
    //     check_utils.showCustToast('商铺类型不能为空')
    //     return false
    // }
    // 面积要求
    if(check_utils.isEmpty(postDto.acreage)){
        check_utils.showCustToast('商铺面积不能为空且须正整数')
        return false
    }
    if(!check_utils.isIntegerGtZero(postDto.acreage)){
        check_utils.showCustToast('商铺面积不能为空且须正整数')
        return false
    }
    if(!check_utils.isIntegerLtValue(postDto.acreage, 1000)){
        check_utils.showCustToast('商铺面积不能大于1000平')
        return false
    }
    // 租金预算
    if(check_utils.isEmpty(postDto.rent)){
        check_utils.showCustToast('月租金不能为空且须正整数')
        return false
    }
    if(!check_utils.isIntegerGtZero(postDto.rent)){
        check_utils.showCustToast('月租金不能为空且须正整数')
        return false
    }
    if(!check_utils.isIntegerLtValue(postDto.rent, 1000000)){
        check_utils.showCustToast('月租金不能大于1000000')
        return false
    }
    
    // 转让费是否面议
    if(check_utils.isEmpty(postDto.transferFeeDiscuss)){
        check_utils.showCustToast('请选择是否接受转让费面议')
        return false
    }
    // 是否接受转让费
    // if(postDto.transferFeeDiscuss == 0){
    //     if(check_utils.isEmpty(postDto.transferFee) || !check_utils.isIntegerGtZero(postDto.transferFee)){
    //         check_utils.showCustToast('转让费不能为空且须为整数')
    //         return false
    //     }
    // }
    if(check_utils.isEmpty(postDto.transferFee)){
        check_utils.showCustToast('转让费不能为空，若无转让费，请填0')
        return false
    }
    if(!check_utils.isIntegerLtValue(postDto.transferFee, 1000000)){
        check_utils.showCustToast('转让费不能大于1000000')
        return false
    }
    // 联系电话
    if(check_utils.isEmpty(postDto.contactPhone)){
        check_utils.showCustToast('联系电话不能为空')
        return false
    }
    if(!check_utils.isMobilePhone(postDto.contactPhone)){
        check_utils.showCustToast('联系电话格式有误')
        return false
    }
    return true
}
export const finishBase = function(postDto){
    if(!check_utils.isNotEmptyWithSomeKey(postDto, ['province', 'city', 'cityCode', 'area', 'areaCode', 'street'])){
        return 0
    }
    if(check_utils.isEmpty(postDto.address) || postDto.address.length < 5){
        return 0
    }
    // 计划经营
    if(check_utils.isEmpty(postDto.industryId)){
        return 0
    }
    // 面积要求
    if(check_utils.isEmpty(postDto.acreage)){
        return 0
    }
    if(!check_utils.isIntegerGtZero(postDto.acreage)){
        return 0
    }
    if(!check_utils.isIntegerLtValue(postDto.acreage, 1000)){
        return 0
    }
    // 租金预算
    if(check_utils.isEmpty(postDto.rent)){
        return 0
    }
    if(!check_utils.isIntegerGtZero(postDto.rent)){
        return 0
    }
    if(!check_utils.isIntegerLtValue(postDto.rent, 1000000)){
        return 0
    }
    
    // 转让费是否面议
    if(check_utils.isEmpty(postDto.transferFeeDiscuss)){
        return 0
    }
    
    // 是否接受转让费
    // if(postDto.transferFeeDiscuss == 0){
    //     if(check_utils.isEmpty(postDto.transferFee) || !check_utils.isIntegerGtZero(postDto.transferFee)){
    //         return 0
    //     }
    // }
    if(check_utils.isEmpty(postDto.transferFee)){
        return 0
    }
    if(!check_utils.isIntegerLtValue(postDto.transferFee, 1000000)){
        return 0
    }
    // 联系电话
    if(check_utils.isEmpty(postDto.contactPhone)){
        return 0
    }
    if(!check_utils.isMobilePhone(postDto.contactPhone)){
        return 0
    }
    return 1
}

export const checkPic = function(postDto){
    if(check_utils.isEmpty(postDto.facadePicture)){
        check_utils.showCustToast('请至少上传一张商铺照片哦')
        return false
    }
    return true
}
export const finishPic = function(postDto){
    if(check_utils.isEmpty(postDto.facadePicture)){
        return 0
    }
    return 1
}

export const checkLicense = function(postDto){
    return true
}
export const finishLicense = function(postDto){
    if(check_utils.isEmpty(postDto.businessLicensePicture)
        && check_utils.isEmpty(postDto.healthLicensePicture)
        && check_utils.isEmpty(postDto.foodLicensePicture)
        && check_utils.isEmpty(postDto.foodProcessLicensePicture)
        && check_utils.isEmpty(postDto.foodCirculeLicensePicture)
        && check_utils.isEmpty(postDto.smokeBusinessLicensePicture)
        && check_utils.isEmpty(postDto.wineBusinessLicensePicture)
        && check_utils.isEmpty(postDto.foodBusinessLicensePicture)
        && check_utils.isEmpty(postDto.envLicensePicture)){
            return 0
        }
    return 1
}

export const checkVideo = function(postDto){
    return true
}
export const finishVideo = function(postDto){
    if(check_utils.isEmpty(postDto.shopVideo)){
        return 0
    }
    return 1
}


export const checkFeature = function(postDto){
    return true
}
export const finishFeature = function(postDto){
    if(check_utils.isEmpty(postDto.content)){
        return 0
    }
    return 1
}

export const checkSell = function(postDto){
    if(!checkBase(postDto)){
        check_utils.showCustToast('请先完善基本信息哦')
        return false
    }
    if(!checkPic(postDto)){
        check_utils.showCustToast('请至少上传一张商铺照片哦')
        return false
    }
    return true
}

const getContentByLen = function(length, postDto){
    if(postDto.content && postDto.content.length >= length){
        return postDto.content.substring(0, length)
    }
    return postDto.content ? postDto.content : ''
}

let getAllPicOfPost = function(postDto){
    let images = []
    if(postDto.facadePicture){
        images = images.concat(postDto.facadePicture.split(','))
    }
    if(postDto.businessLicensePicture){
        images.push(postDto.businessLicensePicture)
    }
    if(postDto.healthLicensePicture){
        images.push(postDto.healthLicensePicture)
    }
    if(postDto.foodLicensePicture){
        images.push(postDto.foodLicensePicture)
    }
    if(postDto.foodProcessLicensePicture){
        images.push(postDto.foodProcessLicensePicture)
    }
    if(postDto.foodCirculeLicensePicture){
        images.push(postDto.foodCirculeLicensePicture)
    }
    if(postDto.smokeBusinessLicensePicture){
        images.push(postDto.smokeBusinessLicensePicture)
    }
    if(postDto.wineBusinessLicensePicture){
        images.push(postDto.wineBusinessLicensePicture)
    }
    if(postDto.foodBusinessLicensePicture){
        images.push(postDto.foodBusinessLicensePicture)
    }
    console.log('发帖的所有图片', images)
    return images
}

let getTransferFeeDesc = function(postDto){
    if(postDto.transferFeeDiscuss == 1){
        return '面议'
    }else if(postDto.transferFee && postDto.transferFee > 0){
        return postDto.transferFee + '万'
    }else{
        return '无转让费'
    }
}

let getTitle = function(postDto){
    if(postDto.postType == Dict.PostMainTypeEnum.Shop.childs.ShopSell.value){
        let industryName = CustomDict.getDictName(postDto.industryId, Dict.IndustryTypeEnum)
        console.log('解析出行业名称', postDto.industryId, industryName)
        return postDto.street + '•' + industryName + '•' + '转店'
    }else{
        let industryName = CustomDict.getDictName(postDto.industryId, Dict.IndustryTypeEnum)
        console.log('解析出行业名称', postDto.industryId, industryName)
        return postDto.street + '•' + industryName + '•' + '找店'
    }
}

let getTitleWithArea = function(postDto){
    if(postDto.postType == Dict.PostMainTypeEnum.Shop.childs.ShopSell.value){
        return postDto.area + '•' + postDto.street + '•' + '转店'
    }else{
        return postDto.area + '•' + postDto.street + '•' + '找店'
    }
}

let canCommentOrContact = function(postDto, doComment = true){
    console.log('校验是否可删除', postDto)
    if(doComment){
        // 检查是否超过留言用户数
        if(Api.CommentApi.overLimitCommentNumber(postDto.userId)){
            check_utils.showCustToast('每日最多给5个用户留言哦～')
            return false
        }
    }
    if(postDto.delFlg == 1){
        check_utils.showCustToast('找铺信息已被删除～')
        return false
    }
    if(postDto.postType == Dict.PostMainTypeEnum.Shop.childs.ShopSell.value){
        if(postDto.postStatus != Dict.PostStatusEnum.Agree.value){
            if(postDto.postStatus == Dict.PostStatusEnum.Finish.value){
                check_utils.showCustToast('店铺已被转出哦～')
            }else{
                check_utils.showCustToast('店铺信息不存在或已被下架～')
            }
            return false
        }
        return true
    }
    return true
}

export const PostUtils = {
    checkBase,
    checkBuy,
    checkPic,
    checkLicense,
    checkVideo,
    checkSell,
    getContentByLen,
    getAllPicOfPost,
    getTransferFeeDesc,
    getTitle,
    getTitleWithArea,
    canCommentOrContact
}
